package com.family.controller;

import com.family.domain.Book;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController//等于@Controller+@Responsebody
@RequestMapping("/books")
public class BookController {

    @PostMapping
    public String save(@RequestBody Book book){//http://localhost:8888/books   请求体的json数据{"type":"rmantic","name":"romio and juiet","description":"a love story"}
        System.out.println("book save ==> "+ book);
        return "{'module':'book save success'}";
    }

    @GetMapping
    public List<Book> getAll(){//http://localhost:8888/books
// [{"id":null,"type":"计算机","name":"SpringMVC入门教程","description":"小试牛刀"},
// {"id":null,"type":"计算机","name":"SpringMVC实战教程","description":"一代宗师"},
// {"id":null,"type":"计算机丛书","name":"SpringMVC实战教程进阶","description":"一代宗师呕心创作"}]
        System.out.println("book getAll is running ...");
        List<Book> bookList = new ArrayList<Book>();

        Book book1 = new Book();
        book1.setType("计算机");
        book1.setName("SpringMVC入门教程");
        book1.setDescription("小试牛刀");
        bookList.add(book1);

        Book book2 = new Book();
        book2.setType("计算机");
        book2.setName("SpringMVC实战教程");
        book2.setDescription("一代宗师");
        bookList.add(book2);

        Book book3 = new Book();
        book3.setType("计算机丛书");
        book3.setName("SpringMVC实战教程进阶");
        book3.setDescription("一代宗师呕心创作");
        bookList.add(book3);

        return bookList;
    }

}














